(ns jumpluff.datasets)

(defmacro update-vec-from-index-map
  "Expand to a cond->, int?, assoc, and let nth"
  [xs index-map binding & {:as body-pairs}]
  `(cond-> ~xs
     ~@(->> body-pairs
          (map (fn [[k v]]
                 (list `(int? (~k ~index-map))
                       `(assoc (~k ~index-map)
                               (let [~binding (nth ~xs (~k ~index-map))]
                                 ~v)))))
          (apply concat))))

;; To define macros at the REPL: append $macros to the namespace
;; but invoke the macro with the public namespace
;; (ns jumpluff.datasets$macros)

;; (let [xs ["val1" "val2" "val3" "val4"]]
;;   (= (jumpluff.datasets/update-vec-from-index-map
;;       xs {:v1 0 :v2 1} <>
;;       :v1 (reverse <>)
;;       :v2 (reverse <>))
;;      (cond-> xs
;;        (int? 1)
;;        (assoc 1 (let [<> (nth xs 1)]
;;                   (reverse <>)))
;;        (int? 0)
;;        (assoc 0 (let [<> (nth xs 0)]
;;                   (reverse <>))))))
;; => true

